import { getAjax, deleteAjax } from '@/utils/request'

import { Mutation, Action } from 'vuex'

export interface JobLog {
  jobLogId?: number | null;
  jobName?: string;
  jobGroup?: string;
  invokeTarget?: string;
  jobMessage?: string;
  status?: string;
  exceptionInfo?: string;
  startTime?: Date | null;
  stopTime?: Date | null;
  createTime?: Date| null;
}

export interface StateType {
  data: JobLog;
}

export interface ModuleType {
  namespaced: boolean;
  state: StateType;
  mutations: {
    SET_DATA: Mutation<StateType>;
  };
  actions: {
    getList: Action<StateType, StateType>;
    getInfo: Action<StateType, StateType>;
    deleteLog: Action<StateType, StateType>;
    clean: Action<StateType, StateType>;
  };
}

const storeModel: ModuleType = {
  namespaced: true,
  state: {
    data: {}
  },
  mutations: {
    SET_DATA: (state, data) => {
      state.data = data
    }
  },
  actions: {
    getList(_, data) {
      return getAjax('/monitor/jobLog/list', data)
    },
    getInfo(_, id) {
      return getAjax(`/monitor/jobLog/${id}`, null)
    },
    deleteLog(_, id) {
      return deleteAjax(`/monitor/jobLog/${id}`, null)
    },
    clean() {
      return deleteAjax('/monitor/jobLog/clean', null)
    }
  }
}

export default storeModel
